package com.wxs.service.impl;


import com.wxs.mapper.NewsMapper;
import com.wxs.po.NewsBean;
import com.wxs.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service("newsServiceImpl")
public class NewsServiceImpl implements NewsService {

	@Autowired
	private NewsMapper newsMapper;


//	@Autowired
//	private CourseMapper courseMapper;

//	@Autowired
//	private StudentCourseMapper studentCourseMapper;
//
//	@Override
//	public void upadteById(Course course) throws Exception {
//		courseMapper.updateByPrimaryKey(course);
//	}

	public List<NewsBean> getNewsList() {
		List<NewsBean> clist = null;
		try {
			List<NewsBean> list = newsMapper.getNewsList();
			clist = new ArrayList<NewsBean>();
			if(list!=null&&list.size()>0){
				for(NewsBean mapl:list){
					NewsBean newsBean=new NewsBean();
					newsBean.setId(mapl.getId());
					newsBean.setTitle(mapl.getTitle());
					newsBean.setConetnt(mapl.getConetnt());
					newsBean.setAuthor(mapl.getAuthor());
					newsBean.setAddtime(mapl.getAddtime());
					clist.add(newsBean);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("错误："+e);
		}
		return clist;
	}




	public NewsBean getNews(String id) {
		NewsBean newsBean= null;
		try {
//			newsBean = null;
//			Object [] obj=new Object[1];
//			obj[0]=id;
			NewsBean news =newsMapper.getNews(id);
			if(news!=null){
				newsBean=new NewsBean();
					newsBean.setId(news.getId());
					newsBean.setTitle(news.getTitle());
					newsBean.setConetnt(news.getConetnt());
					newsBean.setAuthor(news.getAuthor());
					newsBean.setAddtime(news.getAddtime());
				}

		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("错误getNews："+e);
		}
		return newsBean;
	}


}
